# libraries
library(tidyverse)
library(haven)

# read full merge data
df = read_rds("r/replication/data/lapop.rds")


# percent who approve 
supports = df %>% 
  drop_na() %>%
  # feels more warmly than not
  mutate(supports_vig = ifelse(e16 > 5, "Support", "Oppose")) %>% 
  group_by(pais, year, supports_vig) %>%
  summarise(n = n()) %>%
  group_by(pais, year) %>%
  mutate(pct = n/sum(n)) %>%
  filter(supports_vig == "Support")


ggplot(supports, aes(x = fct_reorder(pais, pct), y = pct)) + 
  geom_col(fill = "Coral3", alpha = .9) +
  coord_flip() +
  scale_y_continuous(labels = scales::percent) + 
  hrbrthemes::theme_ipsum(grid = "X") + 
  labs(y = "Percent answering at least 5 out of 10", 
       x = NULL, 
       caption = "`To what extent do you support people taking the law \ninto their own hands when the state is unable to punish criminals?'") +
  theme(legend.position = "none")

ggsave("r/replication/figures/lap-approval.pdf", device = cairo_pdf)


